package com.li;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author lirenchun
 */
public class MultiThread1 {

    public static void main(String[] args) {
        MultiThread1 multiThread1 = new MultiThread1();
        try {
            multiThread1.multiThread1();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

    /**
     * 多线程顺序返回方法1
     */
    public void multiThread1() throws InterruptedException, ExecutionException {
        List<Callable<List<String>>> tasks = new ArrayList<>();
        tasks.add(new Task(1));
        tasks.add(new Task(2));
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        List<Future<List<String>>> futures = executorService.invokeAll(tasks, 3, TimeUnit.MINUTES);
        if (futures.size() > 0) {
            for (Future<List<String>> future : futures) {
                System.out.println(future.get());
            }
        }
    }

}
